package com.blogManager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.blogManager.entity.PageResult;
import com.blogManager.entity.Result;
import com.blogManager.pojo.TbBlogtype;
import com.blogManager.service.BlogTypeService;
import com.sun.org.apache.bcel.internal.generic.RETURN;

@Controller
@RequestMapping("/blogType")
public class BlogTypeController {
	
	@Autowired
	private BlogTypeService blogTypeService;
	
	@RequestMapping("/getBlogTypeList")
	@ResponseBody
	public PageResult getBlogTypeList(int page,int rows) {
		return blogTypeService.getBlogTypeList(page, rows);
	}
	
	@RequestMapping("/search")
	@ResponseBody
	public PageResult search(int page,int rows,@RequestBody TbBlogtype blogType) {
		return blogTypeService.search(page, rows,blogType);
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public Result add(@RequestBody TbBlogtype blogType) {
		try {
			blogTypeService.add(blogType);
			return new Result(true,"添加成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false,"添加失败");
		}
	}
	
	@RequestMapping("/getBlogTypeById")
	@ResponseBody
	public TbBlogtype getBlogTypeById(int typeId) {
		return blogTypeService.getBlogTypeById(typeId);
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public Result update(@RequestBody TbBlogtype blogType) {
		try {
			blogTypeService.update(blogType);
			return new Result(true,"修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false,"修改失败");
		}
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public Result delete(int [] ids) {
		try {
			blogTypeService.delete(ids);
			return new Result(true,"删除成功");
		}catch(Exception e) {
			e.printStackTrace();
			return new Result(false,"删除失败");
		}
	}
	
	@RequestMapping("/findAll")
	@ResponseBody
	public List<TbBlogtype> findAll(){
		return blogTypeService.findAll();
	}
	
}
